package com.fourpigeon.controller;

import com.fourpigeon.domain.*;
import com.fourpigeon.service.BlogGetService;
import com.fourpigeon.service.BlogPublishService;
import com.fourpigeon.service.BlogService;
import com.fourpigeon.service.BlogUpdateService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/blog")
public class BlogController {
    @Autowired
    private BlogService blogService;
    @Autowired
    private BlogUpdateService blogUpdateService;
    @Autowired
    private BlogGetService blogGetService;
    @Autowired
    private BlogPublishService blogPublishService;

    //发布日常贴
    @PostMapping("/daily/publish/{blogType}")
    public Result publishDaily(@RequestBody BlogDailyDTO blogDailyDTO,@PathVariable Short blogType){
        System.out.println(blogDailyDTO);
        return blogPublishService.publishDaily(blogDailyDTO,blogType);
    }

    //更新日常贴
    @PostMapping("/daily/update/{blogId}")
    public Result updateDaily(@RequestBody BlogDailyDTO blogDailyDTO, @PathVariable Long blogId){
        return blogUpdateService.updateDaily(blogDailyDTO,blogId);
    }

    //发布交易贴
    @PostMapping("/deal/publish")
    public Result publishDeal(@RequestBody BlogDealDTO blogDealDTO){
        return blogPublishService.publishDeal(blogDealDTO);
    }

    //更新交易贴
    @PostMapping("/deal/update/{blogId}")
    public Result updateDeal(@RequestBody BlogDealDTO blogDealDTO,@PathVariable Long blogId){
        return blogUpdateService.updateDeal(blogDealDTO,blogId);
    }

    //发布约球贴
    @PostMapping("/agreement/publish/{blogType}")
    public Result publishAgree(@RequestBody BlogAgreeDTO blogAgreeDTO,@PathVariable Short blogType){
        return blogPublishService.publishAgreement(blogAgreeDTO,blogType);
    }

    //更新约球贴
    @PostMapping("/agreement/update/{blogType}/{blogId}")
    public Result updateAgree(@RequestBody BlogAgreeDTO blogAgreeDTO,@PathVariable Short blogType,@PathVariable Long blogId){
        return blogUpdateService.updateAgreement(blogAgreeDTO,blogType,blogId);
    }

    //加入约球贴(已废弃)
    @Deprecated
    @PostMapping("/join/{blogId}")
    public Result joinAgreeBlog(@PathVariable("blogId") Long blogId){
        return blogService.joinAgreeBlog(blogId);
    }

    //发布陪教贴
    @PostMapping("/practice/publish")
    public Result publishPractice(@RequestBody BlogPracticeDTO blogPracticeDTO){return blogPublishService.publishPractice(blogPracticeDTO);}

    //更新陪教贴
    @PostMapping("/practice/update/{blogId}")
    public Result updatePractice(@RequestBody BlogPracticeDTO blogPracticeDTO,@PathVariable Long blogId){
        return blogUpdateService.updatePractice(blogPracticeDTO,blogId);
    }

    //获取日常贴
    @GetMapping("/daily/{blogId}")
    public Result getDaily(@PathVariable Long blogId){
        return blogGetService.getDaily(blogId);
    }

    //获取交易贴
    @GetMapping("/deal/{blogId}")
    public  Result getDeal(@PathVariable Long blogId){
        return blogGetService.getDeal(blogId);
    }

    //获取约球贴
    @GetMapping("/agreement/{blogType}/{blogId}")
    public  Result getAgree(@PathVariable Short blogType,@PathVariable Long blogId){
        return blogGetService.getAgree(blogType,blogId);
    }

    //获取陪教贴
    @GetMapping("/practice/{blogId}")
    public  Result getPractice(@PathVariable Long blogId){
        return blogGetService.getPractice(blogId);
    }

    //发布评论
    @PostMapping("/comment/{blogId}")
    public Result comment(@RequestBody BlogCommentDTO blogCommentDTO ,@PathVariable Long blogId){
        return blogPublishService.comment(blogCommentDTO,blogId);
    }

    //点赞贴子
    @PutMapping("/like/{blogId}")
    public Result likeBlogOrNot(@PathVariable Long blogId){
        return blogService.likeBlogOrNot(blogId);
    }

    //点赞评论
    @PutMapping("/comment/like/{commentId}")
    public Result likeComment(@PathVariable Long commentId){
        return blogService.likeComment(commentId);
    }

    //分页查询日常贴
    @GetMapping("/daily/page/{startId}")
    public Result getDailys(@PathVariable Long startId){
        return blogGetService.getDailys(startId);
    }

    //分页查询交易贴
    @GetMapping("/deal/page/{startId}")
    public Result getDeals(@PathVariable Long startId){
        return blogGetService.getDeals(startId);
    }

    //分页查询约球贴
    @GetMapping("/agreement/page/{blogType}/{startId}")
    public Result getAgrees(@PathVariable Short blogType,@PathVariable Long startId){
        return blogGetService.getAgrees(blogType,startId);
    }

    //分页查询陪教贴
    @GetMapping("/practice/page/{startId}")
    public Result getPractices(@PathVariable Long startId){
        return blogGetService.getPractices(startId);
    }

    //获取一个贴子的评论(分页)
    @GetMapping("/comment/get/{blogId}/{start}")
    public Result getPageComment(@PathVariable Long blogId,@PathVariable Long start){
        return blogGetService.getPageComment(blogId,start);
    }

    @GetMapping("/click/{blogType}/{blogId}")
    public Result clickCount(@PathVariable Integer blogType,@PathVariable Long blogId){return blogService.clickCount(blogType,blogId);}

    @GetMapping("/hotBlog/{blogType}")
    public Result getHotBlog(@PathVariable Integer blogType){
        return blogGetService.getHotBlog(blogType);
    }

    @GetMapping("/SearchDeals/{searchKeyWord}/{type}")
    public Result getSearchDeals(@PathVariable String searchKeyWord, @PathVariable Short type) {
        return blogGetService.getSearchDeals(searchKeyWord, type);
    }

    @GetMapping("/SearchDailies/{searchKeyWord}/{type}")
    public Result getSearchDailies(@PathVariable String searchKeyWord, @PathVariable Short type) {
        return blogGetService.getSearchDailies(searchKeyWord, type);
    }

    @GetMapping("/SearchPractices/{searchKeyWord}/{type}")
    public Result getSearchPractices(@PathVariable String searchKeyWord, @PathVariable Short type) {
        return blogGetService.getSearchPractices(searchKeyWord, type);
    }

    @GetMapping("/SearchAgrees/{searchKeyWord}/{type}/{blogType}")
    public Result getSearchAgrees(@PathVariable String searchKeyWord, @PathVariable Short type, @PathVariable Short blogType) {
        return blogGetService.getSearchAgrees(searchKeyWord, type, blogType);
    }

    @PostMapping("/report/{blogType}/{blogId}")
    public Result reportBlog(@PathVariable Short blogType,@PathVariable Long blogId,@RequestParam String content){return blogService.reportBlog(blogType,blogId,content);}
}
